package com.trajan.exercise.algorithm;

/*

   Created with IntelliJ IDEA.

   Ing. Tomáš Herich
   --------------------------- 
   18. 06. 2013
   5:22 PM

*/

public class ReverseString {

    public static void main (String ... args) {

        ReverseString reverse = new ReverseString();

        System.out.println(reverse.reverseString("Reverse this nice string!"));
        System.out.println(reverse.reverseStringStringBuffer("Reverse this nice string with StringBuffer!"));

    }

    public String reverseString(String originalString) {

        String resultString = "";

        for (int i = 0; i < originalString.length(); i++) {

            char c = originalString.charAt(i);
            resultString = c + resultString;
        }

        return resultString;
    }

    public String reverseStringStringBuffer(String originalString) {

        if (originalString != null) {

        StringBuffer buffer = new StringBuffer(originalString);
        return  buffer.reverse().toString();

        } else {
            return null;
        }
    }

}
